package HomeWork1;

import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;
import org.omg.CORBA.PUBLIC_MEMBER;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Scanner;

/*
 *@Student 张策
 */
//public class Main {
//    public static void main(String[] args) {
//        T t1 = new T();
//        T2 t2 = new T2(t1);
//        t1.start();
//        t2.start();
//    }
//}
//class T extends Thread{
//    private boolean loop=true;
//
//    public void setLoop(boolean loop) {
//        this.loop = loop;
//    }
//
//    @Override
//    public void run() {
//        while (loop){
//        System.out.println(((int) (Math.random() * 100) + 1));
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
//    }
//}
//class T2 extends Thread  {
//    T t;
//    public T2(T t){
//        this.t=t;
//    }
//    Scanner scanner=new Scanner(System.in);
//    @Override
//    public void run() {
//        while (true){
//        char ch=scanner.next().toUpperCase().charAt(0);
//        if(ch=='Q'){
//            t.setLoop(false);
//            break;
//        }
//        }
//    }
//}
public class Main {
    public static void main(String[] args) {
        T t1 = new T();
        T2 t2 = new T2(t1);
        t1.start();
        t2.start();
    }
}
class T extends Thread{
    private boolean loop=true;

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
    @Override
    public void run() {
        while (loop){
            System.out.println(((int) (Math.random() * 100) + 1));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class T2 extends Thread  {
    T t;
    public T2(T t){
        this.t=t;
    }
    Scanner scanner=new Scanner(System.in);
    @Override
    public void run() {
        while (true){
            char ch=scanner.next().toUpperCase().charAt(0);
            if(ch=='Q'){
                t.setLoop(false);
                break;
            }
        }
    }
}
